package com.keon.jianbao.adapter;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.keon.jianbao.AppContext;
import com.keon.jianbao.AppManager;
import com.keon.jianbao.R;
import com.keon.jianbao.base.BaseActivity;
import com.keon.jianbao.base.BaseListAdapter;
import com.keon.jianbao.bean.ListAppraisal;
import com.keon.jianbao.enu.AppraisalStatus;
import com.keon.jianbao.ui.activity.FriendInfoActivity;
import com.keon.jianbao.ui.activity.JianBaoPayWayActivity;
import com.keon.jianbao.ui.widget.ItemLayout;
import com.keon.jianbao.util.UILUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by keon on 2015/9/9.
 */
public class JianBaoListAdapter extends BaseListAdapter {

    static class ViewHolder {
        @Bind(R.id.jianbao_expert)
        ItemLayout ilExpert;
        @Bind(R.id.jianbao_item_img)
        ImageView sdvImg;
        @Bind(R.id.jianbao_item_type)
        TextView tvType;
        @Bind(R.id.jianbao_item_is_fake)
        TextView tvIsFake;
        @Bind(R.id.jianbao_item_name)
        TextView tvName;
        @Bind(R.id.jianbao_item_evaluate)
        TextView tvEvaluate;
        @Bind(R.id.jianbao_item_pay)
        TextView tvPay;
        @Bind(R.id.jianbao_item_rl_pay)
        RelativeLayout rlPay;
/*        @Bind(R.id.jianbao_list)
        NoScrollListView lvList;*/

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_jianbao, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        final ListAppraisal listAppraisal = (ListAppraisal) mDatas.get(position);
        vh.ilExpert.setTitle(listAppraisal.getExpert_name2());

//        Uri uri = Uri.parse(listAppraisal.getAppraisal_image());
//        vh.sdvImg.setImageURI(uri);
        ImageLoader.getInstance().displayImage(listAppraisal.getAppraisal_image(), vh.sdvImg, UILUtils.getOptions2());

        vh.tvType.setText(listAppraisal.getAppraisal_catalog());
        vh.tvName.setText(listAppraisal.getAppraisal_name());

        if (listAppraisal.getStatus() == AppraisalStatus.APPRAISALED.getStatus()) {
            vh.tvEvaluate.setText(listAppraisal.getExpert_appraisal_detail());
            vh.tvIsFake.setText(listAppraisal.getExpert_appraisal_result());
//            vh.tvPay.setVisibility(View.GONE);
        } else if (listAppraisal.getStatus() == AppraisalStatus.APPRAISAL.getStatus()) {
            vh.tvEvaluate.setText(listAppraisal.getAppraisal_desc());
            vh.tvIsFake.setText(listAppraisal.getCreate_time());
//            vh.tvPay.setVisibility(View.GONE);
        } else if (listAppraisal.getStatus() == AppraisalStatus.BACK.getStatus()) {
            vh.tvEvaluate.setText("退回原因：" + listAppraisal.getExpert_refuse_detail());
            vh.tvIsFake.setText(AppraisalStatus.BACK.getName());
//            vh.tvPay.setVisibility(View.GONE);
        } else if (listAppraisal.getStatus() == AppraisalStatus.UNPAID.getStatus()) {
//            vh.tvPay.setVisibility(View.VISIBLE);
            vh.tvIsFake.setText(listAppraisal.getStatus_alias());
            vh.tvEvaluate.setText(listAppraisal.getAppraisal_desc());
            vh.rlPay.setVisibility(View.VISIBLE);
            vh.tvPay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("appraisal_id", listAppraisal.getId());
                    BaseActivity ba = (BaseActivity) AppManager.getAppManager().currentActivity();
                    ba.jump(JianBaoPayWayActivity.class, bundle);
                }
            });
        }



/*        JianBaoItemList jianBaoItemList = new JianBaoItemList("");
        JianBaoItemListAdapter adapter = new JianBaoItemListAdapter((ArrayList) jianBaoItemList.getList());
        vh.lvList.setAdapter(adapter);*/

        return convertView;
    }
}
